/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  net.sf.ehcache.Cache
 *  net.sf.ehcache.CacheManager
 *  net.sf.ehcache.Element
 *  org.springframework.cache.ehcache.EhCacheCacheManager
 */
package com.gys.common.util;

import com.gys.common.util.SpringUtil;
import java.io.Serializable;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.springframework.cache.ehcache.EhCacheCacheManager;

public class CacheUtil {
    private static CacheManager cacheManager = ((EhCacheCacheManager)SpringUtil.getBean("cacheManager")).getCacheManager();
    public static final String SYS_CACHE = "sysCache";

    public static Object get(String key) {
        return CacheUtil.get(SYS_CACHE, key);
    }

    public static void put(String key, Object value) {
        CacheUtil.put(SYS_CACHE, key, value);
    }

    public static void remove(String key) {
        CacheUtil.remove(SYS_CACHE, key);
    }

    private static Object get(String cacheName, String key) {
        Element element = CacheUtil.getCache(cacheName).get((Serializable)(key));
        return element == null ? null : element.getObjectValue();
    }

    private static void put(String cacheName, String key, Object value) {
        Element element = new Element(key, value);
        CacheUtil.getCache(cacheName).put(element);
    }

    private static void remove(String cacheName, String key) {
        CacheUtil.getCache(cacheName).remove((Serializable)(key));
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private static Cache getCache(String cacheName) {
        CacheManager cacheManager = CacheUtil.cacheManager;
        synchronized (cacheManager) {
            Cache cache = CacheUtil.cacheManager.getCache(cacheName);
            if (cache == null) {
                CacheUtil.cacheManager.addCache(cacheName);
                cache = CacheUtil.cacheManager.getCache(cacheName);
                cache.getCacheConfiguration().setEternal(true);
            }
            return cache;
        }
    }

    public static CacheManager getCacheManager() {
        return cacheManager;
    }
}

